package com.newgoldcurrency.activities;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.Html;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;

import com.newgoldcurrency.R;
import com.newgoldcurrency.databinding.ActivitySurpriseBinding;

import java.util.Objects;

public class SurpriseActivity extends AppCompatActivity {
    private ActivitySurpriseBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySurpriseBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setResult(2);
        binding.surpriseTxt.setText(Html.fromHtml("Lucky to get a surprise reward, the reward may be delayed, go to my mining to check" + "<img src='" + R.drawable.arrow_right + "'/>", source -> {
            int id = Integer.parseInt(source);
            Drawable drawable = ResourcesCompat.getDrawable(getResources(),id,null);
            Objects.requireNonNull(drawable).setBounds(0, 0, drawable.getIntrinsicWidth()-10 , drawable.getIntrinsicHeight()-10);
            return drawable;
        }, null));
        binding.surpriseTxt.setOnClickListener(view -> {
            if (checkDoubleClick()){
                setResult(3);
                finish();
            }
        });
        binding.surpriseCheck.setOnClickListener(view -> {
            if (checkDoubleClick()){
                setResult(3);
                finish();
            }
        });
    }
    private long mClickTime;
    private boolean checkDoubleClick() {
        boolean result= mClickTime < SystemClock.uptimeMillis() - 500;
        mClickTime = SystemClock.uptimeMillis();
        return result;
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding=null;
    }
}